﻿<h3 align='center'>QUẢN LÝ THU</H3>
	<form action="add_thu.php" method="post">
			<table width='100%'>
				<tr valign='top'>
					<td>Mã Thu</td>
					<td><input type='text' name='mathu'/></td>
					<td rowspan='7' width='500'>
						<table border='1' width='100%'>
							<tr>
								<td colspan='4'>
									<h3>THỐNG KÊ</H3>
								</td>
							</tr>
							<tr>
								<td colspan='2'>Tổng Thu</td>
								<td colspan='2'>
								<?php
										$sql_tong="SELECT sum(TongTienThu) as Tong FROM thu";
										$query_tong=mysql_query($sql_tong);
										$r_tong=mysql_fetch_array($query_tong);
										if($r_tong['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_tong['Tong'], 0, ',', '.')."</b>";
										}
									?>
								</td>	
							</tr>
							<tr>
								<td>Tổng Thu Tháng 1</td>
								<td>
									<?php
										$sql_thang1="SELECT sum(TongTienThu) as Tong FROM thu WHERE MONTH(NgayThu)='01'";
										$query_thang1=mysql_query($sql_thang1);
										$r_thang1=mysql_fetch_array($query_thang1);
										if($r_thang1['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_thang1['Tong'], 0, ',', '.')." VNĐ </b>";
										}
									?>
								</td>
								<td>Tổng Thu Tháng 7</td>
								<td>
								<?php
										$sql_thang7="SELECT sum(TongTienThu) as Tong FROM thu WHERE MONTH(NgayThu)='07'";
										$query_thang7=mysql_query($sql_thang7);
										$r_thang7=mysql_fetch_array($query_thang7);
										if($r_thang7['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_thang7['Tong'], 0, ',', '.')." VNĐ </b>";
										}
									?>
								</td>
							</tr>
							<tr>
								<td>Tổng Thu Tháng 2</td>
								<td>
								<?php
										$sql_thang2="SELECT sum(TongTienThu) as Tong FROM thu WHERE MONTH(NgayThu)='02'";
										$query_thang2=mysql_query($sql_thang2);
										$r_thang2=mysql_fetch_array($query_thang2);
										if($r_thang2['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_thang2['Tong'], 0, ',', '.')." VNĐ </b>";
										}
									?>
								
								</td>
								<td>Tổng Thu Tháng 8</td>
								<td>
								<?php
										$sql_thang8="SELECT sum(TongTienThu) as Tong FROM thu WHERE MONTH(NgayThu)='08'";
										$query_thang8=mysql_query($sql_thang8);
										$r_thang8=mysql_fetch_array($query_thang8);
										if($r_thang8['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_thang8['Tong'], 0, ',', '.')." VNĐ </b>";
										}
									?>
								</td>
							</tr>
							<tr>
								<td>Tổng Thu Tháng 3</td>
								<td>
									<?php
										$sql_thang3="SELECT sum(TongTienThu) as Tong FROM thu WHERE MONTH(NgayThu)='03'";
										$query_thang3=mysql_query($sql_thang3);
										$r_thang3=mysql_fetch_array($query_thang3);
										if($r_thang3['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_thang3['Tong'], 0, ',', '.')." VNĐ </b>";
										}
									?>
								</td>
								<td>Tổng Thu Tháng 9</td>
								<td>
								<?php
										$sql_thang9="SELECT sum(TongTienThu) as Tong FROM thu WHERE MONTH(NgayThu)='09'";
										$query_thang9=mysql_query($sql_thang9);
										$r_thang9=mysql_fetch_array($query_thang9);
										if($r_thang9['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_thang9['Tong'], 0, ',', '.')." VNĐ </b>";
										}
									?>
								</td>
							</tr>
							<tr>
								<td>Tổng Thu Tháng 4</td>
								<td>
								<?php
										$sql_thang4="SELECT sum(TongTienThu) as Tong FROM thu WHERE MONTH(NgayThu)='04'";
										$query_thang4=mysql_query($sql_thang4);
										$r_thang4=mysql_fetch_array($query_thang4);
										if($r_thang4['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_thang4['Tong'], 0, ',', '.')." VNĐ </b>";
										}
									?>
								</td>
								<td>Tổng Thu Tháng 10</td>
								<td>
								<?php
										$sql_thang10="SELECT sum(TongTienThu) as Tong FROM thu WHERE MONTH(NgayThu)='10'";
										$query_thang10=mysql_query($sql_thang10);
										$r_thang10=mysql_fetch_array($query_thang10);
										if($r_thang10['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_thang10['Tong'], 0, ',', '.')." VNĐ </b>";
										}
									?>
								</td>
							</tr>
							<tr>
								<td>Tổng Thu Tháng 5</td>
								<td>
								<?php
										$sql_thang5="SELECT sum(TongTienThu) as Tong FROM thu WHERE MONTH(NgayThu)='05'";
										$query_thang5=mysql_query($sql_thang5);
										$r_thang5=mysql_fetch_array($query_thang5);
										if($r_thang5['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_thang5['Tong'], 0, ',', '.')." VNĐ </b>";
										}
									?>
								</td>
								<td>Tổng Thu Tháng 11</td>
								<td>
									<?php
										$sql_thang11="SELECT sum(TongTienThu) as Tong FROM thu WHERE MONTH(NgayThu)='11'";
										$query_thang11=mysql_query($sql_thang11);
										$r_thang11=mysql_fetch_array($query_thang11);
										if($r_thang11['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_thang11['Tong'], 0, ',', '.')." VNĐ </b>";
										}
									?>
								</td>
							</tr>
							<tr>
								<td>Tổng Thu Tháng 6</td>
								<td>
								<?php
										$sql_thang6="SELECT sum(TongTienThu) as Tong FROM thu WHERE MONTH(NgayThu)='06'";
										$query_thang6=mysql_query($sql_thang6);
										$r_thang6=mysql_fetch_array($query_thang6);
										if($r_thang6['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_thang6['Tong'], 0, ',', '.')." VNĐ </b>";
										}
									?>
								</td>
								<td>Tổng Thu Tháng 12</td>
								<td>
								<?php
										$sql_thang12="SELECT sum(TongTienThu) as Tong FROM thu WHERE MONTH(NgayThu)='12'";
										$query_thang12=mysql_query($sql_thang12);
										$r_thang12=mysql_fetch_array($query_thang12);
										if($r_thang12['Tong']==NULL)
										{
											echo "0";
										}
										else
										{
											echo "<b>".number_format($r_thang12['Tong'], 0, ',', '.')." VNĐ </b>";
										}
									?>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>Ngày Thu</td>
					<td><input type='text' name='ngaythu'/></td>
				</tr>
				<tr>
					<td>Loại Thu</td>
					<td>
                    	<select name="loaithu">
						<?php
							$query_loai=mysql_query("SELECT MaLoai,TenLoai FROM loaithuchi ORDER BY MaLoai DESC");
							while($rloai=mysql_fetch_array($query_loai))
							{
                        	echo "<option value='".$rloai['MaLoai']."'>".$rloai['TenLoai']."</option>";
							}
						?>
                        </select>
                    </td>
				</tr>
				<tr>
					<td>Số Lượng</td>
					<td><input type='text' name='soluong'/></td>
				</tr>
				<tr>
					<td>Đơn Vị Tính</td>
					<td><input type='text' name='dvt'/></td>
				</tr>
				<tr>
					<td>Tổng Tiền</td>
					<td><input type='text' name='tongtien'/></td>
				</tr>
                <tr>
                	<td>&nbsp;</td>
					<td><input type="submit" name="luu" value="Lưu Lại"/></td>
                </td>
			</table>
		</form>
			<table width="100%" cellspacing='0' cellpadding='0'>
				<tr align='left' bgcolor='#ccc'>
					<th>Mã Chi</th>
					<th>Ngày Chi</th>
					<th>Tên Loại</th>
					<th>Số Lượng</th>
					<th>ĐVT</th>
					<th>Thành Tiền</th>
					<th>&nbsp;</th>
					<th>&nbsp;</th>
				</tr>
				<?php
					$sql="SELECT MaThu, NgayThu,TenLoai,SoLuong,DVT,TongTienThu FROM thu LEFT OUTER JOIN loaithuchi ON loaithuchi.MaLoai=thu.MaLoai ORDER BY MaThu DESC";
					$query=mysql_query($sql);
					$n=mysql_num_rows($query);
					if($n<=0)
					{
						echo "Chưa có dữ liệu";
					}
					else
					{
					while($r=mysql_fetch_array($query))
					{
				?>
				<tr>
					<td><?php echo $r['MaThu']; ?></td>
					<td><?php echo $r['NgayThu']; ?></td>
					<td><?php echo $r['TenLoai']; ?></td>
					<td><?php echo $r['SoLuong']; ?></td>
					<td><?php echo $r['DVT']; ?></td>
					<td><?php echo $r['TongTienThu']; ?></td>
					<td><img src='img/edit.png' width='30' height='30'></td>
					<td><img src='img/delete-icon.png' width='25' height='25'></td>
				</tr>
				<?php } } ?>
			</table>